<%@ page contentType="text/html;charset=UTF-8" language="java"  import="java.util.*" trimDirectiveWhitespaces="true" %>
<%@include file="/WEB-INF/pages/common/taglib.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>主石单价修改</title>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <%@include file="/WEB-INF/pages/common/commonCss.jsp"%>
    <link rel="stylesheet" href="${basePath}/resources/css/colorpicker.css" />
    <link rel="stylesheet" href="${basePath}/resources/css/datepicker.css" />
    <link rel="stylesheet" href="${basePath}/resources/css/uniform.css" />
    <link rel="stylesheet" href="${basePath}/resources/css/select2.css" />
    <link rel="stylesheet" href="${basePath}/resources/css/matrix-style.css" />
    <link rel="stylesheet" href="${basePath}/resources/css/matrix-media.css" />
    <link rel="stylesheet" href="${basePath}/resources/css/bootstrap-wysihtml5.css" />


</head>
<style>
    .select2-container {
        float:left;
        width: 35%;
    }
    em,strong{ color:#C00;}
    span.error{color:#C00; padding:0 6px;}

</style>
<body>

<!--Header-part-->
<%@include file="/WEB-INF/pages/common/head.jsp"%>


<!--sidebar-menu-->
<%@include file="/WEB-INF/pages/common/left.jsp"%>

<div id="content">
    <div id="content-header">
        <div id="breadcrumb"> <a href="#" title="Go to Home" class="tip-bottom"><i class="icon-home"></i> </a>
            <a href="#" class="current">主石单价新增</a> </div>
        <%--<h1>平台商品新增</h1>--%>
    </div>

    <div class="container-fluid">


        <div class="row-fluid">
            <div class="span12">
                <div class="widget-box">
                    <div class="widget-title"> <span class="icon"> <i class="icon-align-justify"></i> </span>
                        <h5></h5>
                    </div>
                    <div class="widget-content nopadding">
                        <form  id="form" method="POST" class="form-horizontal" >
                            <input type="hidden" name="id" value="${diamondcalculation.id}" id="id">

                            <%--<div class="control-group" >--%>
                                <%--<label class="control-label">重量级别:</label>--%>
                                <%--<div class="controls">--%>
                                    <%--<select  name="weightlevel"  id="weightlevel"   >--%>
                                        <%--<c:forEach items="${weightlevels}" var="level">--%>
                                            <%--<option value="${level.codevalue}" ${level.codevalue==diamondcalculation.weightlevel?'selected':''} disabled>${level.dictname}</option>--%>
                                        <%--</c:forEach>--%>
                                    <%--</select>--%>
                                    <%--<span style="color: green">范围包括头，不包括尾（如0.15ct 请选0.15ct~0.20ct范围）</span>--%>
                                <%--</div>--%>
                            <%--</div>--%>


                            <div class="control-group">
                                <label class="control-label">重量级别起始值(包含):</label>
                                <div class="controls">
                                    <div class="input-append">
                                        <input type="number" name="start"  id="start" placeholder="0" class="span11"  value="${diamondcalculation.start}" required >
                                        <span class="add-on">克拉</span> </div>
                                </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label">重量级别结束值:</label>
                                <div class="controls">
                                    <div class="input-append">
                                        <input type="number" name="end" id="end"  placeholder="0" class="span11"  value="${diamondcalculation.end}" required >
                                        <span class="add-on">克拉</span> </div>
                                </div>
                            </div>



                            <div class="control-group">
                                <label class="control-label">标准单价:</label>
                                <div class="controls">
                                    <div class="input-append">
                                        <input type="number" name="price"  placeholder="0" class="span11"  value="${diamondcalculation.price==null?'':(tz:formatDouble(diamondcalculation.price))}" required >
                                        <span class="add-on">元</span> </div>
                                </div>
                            </div>


                            <div class="control-group">
                                <div class="controls">
                                    <button  type="submit"  onclick="" class="btn btn-success">保存</button>
                                    <button type="reset" class="btn btn-default" onclick="history.go(-1)">返回</button>
                                </div>
                            </div>

                        </form>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>


<!-- Modal -->

</div>



<!--Footer-part-->
<%@include file="/WEB-INF/pages/common/footer.jsp"%>

<!--end-Footer-part-->

<%@include file="/WEB-INF/pages/common/commonJS.jsp"%>
<%--<script src="${basePath}/resources/js/bootstrap.min.js"></script>--%>
<script src="${basePath}/resources/js/jquery.validate.js"></script>
<script src="${basePath}/resources/js/admin/validate.js"></script>


<script>
    $(function(){
        //jquery.validate
        $("#form").validate({
            submitHandler: function() {
                //验证通过后 的js代码写在这里
                var $form = $(form);
                var data = $form.serialize();
                console.log(JSON.stringify(data));
                var start = $("#start").val();
                var end = $("#end").val();
                var obj = {start:start,end:end};
                diamondcalculation.getCountRecord(obj, function () {
                    diamondcalculation.update(data);
                });
//                var weightlevel = $("#weightlevel").val();
//                diamondcalculation.update(data);

            }
        })

    })

    var diamondcalculation = {
        //查询系列是否已经存在
        getCountRecord:function (obj,callback) {
            $.ajax({
                url:adminPath+"/service/diamondcalculation/getCountRecord",
                type:"post",
                data:obj,
                success:function (data) {
                    console.log(data);
                    if(!data){
                        loading("编辑失败",5);
                    }else{
                        console.log(data.id==$("#id").val());
                        if(data.id==$("#id").val() && data.count<=1){
                            //保存
                            if(callback)callback();
                        }else{
                            loading("该范围值和其他范围冲突，请核实",5);
                        }

                    }

                }
            });
        },
        //更新
        update:function (data) {
            $.ajax({
                url:adminPath +'/service/diamondcalculation/update',
                type:'POST',
                data:data,
                success:function (data) {
                    if(data == 1){
                        loading('修改成功',3);
                        window.location.href =  adminPath +"/service/diamondcalculation/list";
                    }
                }
            });
        }
        
    };

</script>

</body>
</html>
